package org.dwpd.config;

import jakarta.annotation.Resource;
import org.dwpd.interceptor.LoginInterceptor;
import org.dwpd.interceptor.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Package:org.dwpo.config
 *
 * @ClassName:WebMvcConfig
 * @Create:2024/5/13 23:05
 **/
//前端配置类
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(stringRedisTemplate))
                .excludePathPatterns(
                        "/user/reqEmailCode/**",
                        "/user/login",
                        "/user/regist/**",
                        "/user/forgetPassword",
                        "/search/searchMessages/**",
                        "/search/filters/**",
                        "/search/suggestion/**"
                ).order(1);
        //order表示权重，权重越低则越早执行拦截
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
